﻿namespace PreGUI.Widgets
{
    using UnityEngine;
    using UnityEngine.UI;
    using PreGUI.Interfaces;
    using PreGUI.Helpers;

    /// <summary>
    /// PreGui Caption Label Control
    /// </summary>
    public class PGCaptionLabel : IPGControl
    {
        private string _caption;

        public GameObject LayoutControls(PreGui gui, GameObject parent, string windowName)
        {
            var gameObject = new GameObject("PGCaptionLabel");
            gameObject.transform.SetParent(parent.transform, false);

            var textComponent = gameObject.AddComponent<Text>();
            textComponent.font = gui.CaptionLabelSettings.Font;
            textComponent.fontSize = gui.CaptionLabelSettings.FontSize;
            textComponent.fontStyle = gui.CaptionLabelSettings.FontStyle;
            textComponent.color = gui.CaptionLabelSettings.FontColor;
            textComponent.text = _caption;

            return gameObject;
        }


        public IPGControl GenerateFromXmlNode(System.Xml.XmlNode node)
        {
            _caption = node.InnerText.Trim();

            return this;
        }
    }
}

